<?php
require_once ($_SERVER['DOCUMENT_ROOT'].'/conf/global.config.php');
require_once (SRC_DIR.'util.php');



$urldata = file_get_contents('php://input');

Util::Logger($urldata,"yiyou_pay");

if (empty($urldata)) {
  ExitAndLog("UrlError");
}
$json = json_decode($urldata);
//$urldata = file_get_contents('php://input');

if (!isset($json->UserId, $json->Code, $json->ItemId, $json->TranId, $json->Amount))
{
  ExitAndLog("Param Error");
}
if ($json->Code != 1)
{
   ExitAndLog("Code Error");
}

$uid = $json->UserId;
$order_no = $json->TranId; //渠道订单
$game_order = $json->ItemId;//游戏订单
$amount = $json->Amount;
$spid = "yiyou";
$account = $spid."_".$uid;

$opid_arr = explode('_',$game_order);
if (count($opid_arr) > 3)
{
    $userid = $opid_arr[1];//account_id
    $role_id = $opid_arr[3];
    $server_id = $opid_arr[0];
}
else
{
   ExitAndLog("OrderCountError");
}
$pay_param = array(
    "opid"  => $order_no,
    "account" => $account,
    "money" => $amount,
    "channel" => $spid,
    "serverid" => $server_id,
    "userid" => $userid,
    "actorid" =>$role_id,
);

$pay_url = "http://212.64.32.16/bg02/api/paycenter.php?".http_build_query($pay_param);

$result = file_get_contents($pay_url);
if ($result == "0" || $result == 0)
  ExitAndLog("success");
else
  ExitAndLog("fail:".$result);

function ExitAndLog($msg)
{
    Util::Logger("$msg","yiyou_pay");
    exit($msg);
}